package com.zenika.zenbinding.client.validator;

import java.util.List;

import com.zenika.zenbinding.client.exception.DataMessage;
import com.zenika.zenbinding.client.exception.ValidatorException;

public class MaxSelectedValidator implements Validator {

	private int max;

	public MaxSelectedValidator(int maxNumber) {
		this.max = maxNumber;
	}

	public void validate(Object object) throws ValidatorException {
		List list = (List) object;
		int size = list.size();
		if (size > this.max) {
			throw new ValidatorException(new DataMessage("You must select less than" + this.max + " items"));
		}
	}

}
